package in.muton.panels.paginator.components.badges;

import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.pages.common.EdusharePanel;
import in.muton.edushare.pages.deptpages.DeptBatches;
import in.muton.edushare.pages.deptpages.DeptPage;
import in.muton.edushare.pages.univ.UnivPage;
import in.muton.edushare.url.EntityPageParams;
import in.muton.edushare.wicket.models.CayenneModel;
import in.muton.panels.paginator.badgehelpers.course.ProgramBadgeInterface;
import in.muton.panels.paginator.helpers.deletelinks.CurriculaRemove;
import in.muton.panels.paginator.helpers.links.CurriculaLink;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import com.edushare.common.vo.Curricula;
import com.edushare.common.vo.Departments;
import com.edushare.common.vo.Universities;

public class CurriculaBadge extends EdusharePanel {

	private static final long serialVersionUID = 398434231741111050L;

	public CurriculaBadge(String id, EduShareBasePage page,
			IModel<Curricula> model, ProgramBadgeInterface pbif) {
		super(id, model, page);
		this.currModel = model;
		this.page = page;
		add(CSSPackageResource.getHeaderContribution(CurriculaBadge.class,
				"badge.css"));
		add(new CurriculaLink("nameLink", currModel, "name"));

		add(new BookmarkablePageLink<Void>("univ", UnivPage.class,
				EntityPageParams.getParams(new CayenneModel<Universities>(
						currModel.getObject().getUniversity()))));

		add(new BookmarkablePageLink<Void>("dept", DeptPage.class,
				EntityPageParams.getParams(new CayenneModel<Departments>(
						currModel.getObject().getDepartment()))));

		add(new Link<Void>("batches") {
			private static final long serialVersionUID = -3772664341445169146L;

			@Override
			public void onClick() {
				PageParameters p = EntityPageParams
						.getParams(new Model<Departments>(currModel.getObject()
								.getDepartment()));
				Integer i = p.size();
				p.add(i.toString(), currModel.getObject().getCurriculaId()
						.toString());
				setResponsePage(DeptBatches.class, p);
			}
		});
		add(new CurriculaRemove("deleteLink", this, currModel, pbif));
	}

	EduShareBasePage page = null;
	private IModel<Curricula> currModel;
}
